<template>
	<view class="content">
		<swiper class="home-banner" :indicator-dots="true" :autoplay="true" :interval="3000">
			<swiper-item v-for="item in BannerData" :key="item.id" @click="onProductsItemTap(item.key_word)">
				<u-image width="100%" height="100%" :src="item.url" mode="aspectFill">
					<u-loading slot="loading"></u-loading>
				</u-image>
			</swiper-item>
		</swiper>

		<view class="home-main">
			<view class="home-main-theme">
				<view class="home-main-header">精选主题</view>
				<view class="theme-box" :class="{'theme-box-square':item.id < 3}" v-for="(item,index) in ThemesItem"
					:key="item._id" @click="onThemesItemTap(item.id,item.name)">
					<u-image width="100%" height="100%" :src="item.topicImgUrl" mode="aspectFill">
						<u-loading slot="loading"></u-loading>
					</u-image>
				</view>
			</view>
			
			<view class="home-main-products">
				<view class="home-main-header">最近新品</view>
				<product-card :data="RecentData" @onProductsItemTap="onProductsItemTap"></product-card>
			</view>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js';
	export default {
		mixins: [badgeMix],
		data() {
			return {
				BannerData: [],
				ThemesItem: [],
				RecentData: [],
				// src: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-bec38ee9-80e0-452a-921e-27d4b264e3b0/9f08fc72-8119-4c68-8f5f-cc5899df7bb8.png"
			}
		},
		async onLoad() {
			let BannerData = await uniCloud.callFunction({
				name: 'getBannerData'
			})
			this.BannerData = BannerData.result.data
			// console.log(BannerData.result.data); 

			let ThemesItem = await uniCloud.callFunction({
				name: 'getThemeData'
			})
			this.ThemesItem = ThemesItem.result.data
			// console.log(ThemesItem);

			let RecentData = await uniCloud.callFunction({
				name: 'getRecent'
			})
			this.RecentData = RecentData.result.data
			console.log(this.RecentData);
		},
		methods: {
			onProductsItemTap(id) {
				uni.navigateTo({
					url: "/page_roduct_detail/product/product?id=" + id
				})
			},
			onThemesItemTap(id, name) {
				uni.navigateTo({
					url: "../theme/theme?id=" + id + "&name=" + name
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		width: 750rpx;
		height: 100vh;
	}

	.content {

		display: flex;
		flex-direction: column;

		width: 750rpx;
		height: 100vh;

		image {
			width: 100%;
			height: 100%;
		}

		.home-banner {
			width: 750rpx;
			height: 400rpx;
		}

		.home-main {

			width: 750rpx;
			height: 100vh;

			.home-main-theme {

				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;

				.home-main-header {
					width: 750rpx;
					text-align: center;
					margin: 20rpx 0;
					color: #AD956B;
				}

				.theme-box {
					width: 750rpx;
					height: 400rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.theme-box-square {
					width: 370rpx;
					height: 375rpx;
					margin-bottom: 10rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}

			}




		}

		.home-main-header {
			text-align: center;
			margin: 20rpx 0;
			color: #AD956B;
		}

		.home-main-products {
			margin-bottom: var(--window-bottom);
		}
	}
</style>
